﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Maticsoft.DBUtility
{
    public abstract class Cldate
    {
        public abstract string acceptcash();
      
    }
    class onedate : Cldate //20100706 格式
    {
        public override string acceptcash()
        {
            string datesql = "select CONVERT(varchar(100), GETDATE(), 112)";
            string tt = Class1.cmdscalar(datesql);
            return tt;
        }
    }
    class twodate : Cldate //1007 格式
    {
        public override string acceptcash()
        {
            string datesql = "select CONVERT(varchar(100), GETDATE(), 112)";
            string tt = Class1.cmdscalar(datesql);
            tt = tt.Substring(2, 4);
            return tt;
        }
    }
    class threedate : Cldate //2010-10-07 格式
    {
        public override string acceptcash()
        {
            string datesql = "select CONVERT(varchar(100), GETDATE(), 23)";
            string tt = Class1.cmdscalar(datesql);
            //tt = tt.Substring(2, 4);
            return tt;
        }
    }
    class fourdate : Cldate //1010071135 加上小时分格式
    {
        public override string acceptcash()
        {
            string datesql = "select replace(replace(replace(convert(varchar(16),getdate(),120),'-',''),' ',''),':','')";
            string tt = Class1.cmdscalar(datesql);
            tt = tt.Substring(2, 10);
            return tt;
        }
    }
    class fivedate : Cldate //100706 格式
    {
        public override string acceptcash()
        {
            string datesql = "select CONVERT(varchar(100), GETDATE(), 112)";
            string tt = Class1.cmdscalar(datesql);
            tt = tt.Substring(2, 6);
            return tt;
        }
    }
    public class cashfactory
    {
        public static Cldate createcashaccept(string type)
        {
            Cldate cs = null;
            switch (type)
            {
                case "1"://20100706
                    cs=new onedate();
                    break;
                case "2"://1007
                    cs = new twodate();
                    break;
                case "3"://2010-10-07
                    cs = new threedate();
                    break;
                case "4"://1010071135
                    cs = new fourdate();
                    break;
                case "5"://100711
                    cs = new fivedate();
                    break;
            }
            return cs;
        }
    }
}
